<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li class="active">
				电影排期列表
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">检索电影票</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">影片名称</label>
					    <div class="col-sm-4">
					      <input type="text" class="form-control" id="movieName" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">影院名称</label>
					    <div class="col-sm-4">
					      <input type="text" class="form-control" id="filmName" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">影院地址</label>
					    <div class="col-sm-4">
					      <input type="text" class="form-control" id="filmAddress" />
					    </div>
				  	</div>
					<div class="form-group panel-cont">
					    <label for="startDate" class="col-sm-2 control-label">开始日期</label>
					    <div class="col-sm-2 selectDate">
					   		<input type='text' readonly="readonly" class='form-control selectData' id='startDate' name='date' value='' />
					   		<i class="fa fa-calendar"></i>  
					    </div>
					    <label for="endDate" class="col-sm-2 control-label">结束日期</label>
					    <div class="col-sm-2 selectDate">
					    	<input type='text' readonly="readonly" class='form-control selectData' id='endDate' name='date' value='' />
					    	<i class="fa fa-calendar"></i>
					    </div>
					    <span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	选择影片开场时间的区间
					    </span>
				  	</div>
				  	<div class="form-group">
				  		<div class="col-sm-5 col-sm-offset-5">
				  			<button type="button" class="btn btn-primary query-btn">查询</button>
				  			<button type="reset" class="btn reset-btn">重置</button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-bottom">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">电影票列表</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="row table-btn">
					<div class="col-sm-12">
						<button type="button" class="btn btn-success sure-btn">确认购票选择&nbsp;<i class="fa fa-plus"></i></button>
					</div>
				</div>
				<div class="panel-body table-body">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th class="hidden-xs"></th>
								<th class="hidden-xs">ID</th>
								<th class="hidden-xs">影片名称</th>
								<th class="hidden-xs">影院名称</th>
								<th class="hidden-xs">影院地址</th>
								<th class="hidden-xs">影厅</th>
								<th class="hidden-xs">开场时间</th>
								<th class="hidden-xs">价格</th>
								<th class="hidden-xs">电影版本</th>
							</tr>
						</thead>
						<tbody>
							
							
						</tbody>
					</table>
					<div class="M-box3 page-style"></div>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
	/*********************************变量*******************************************/
	var pageNo = 1;    // 第几页
	var pageSize = 10; // 每页几条
	var totalPage;     // 总页数
	var totalData;     // 总条数
	var username = GetQueryString("username");    // 用户姓名
	var token = MXCookie.get("token",token);      // 登陆token  	
	var idArr = [];
	/*********************************事件*******************************************/
	datePicker($("#startDate"));  // 开始时间
	datePicker($("#endDate"));    // 结束时间
	$("body").removeAttr("data-ticketnum");  // 初始化

	// 确认购票选择
	$(".page-cont").on("click",".checkTicket",function(){
		var index = $(".checkTicket").index(this);
		if($(this).is(':checked') == true){
			$(this).addClass('checked');
		}else{
			$(this).removeClass('checked');
		}
	});
	$(".sure-btn").click(function(){
		if($(".checked").length == 0){
			alert("至少选择一张电影票");
		}else{
			for( var i = 0; i < $(".checked").length; i ++){
				idArr.push($(".checked").eq(i).attr("data-id"));
			}	
			localStorage.idArr = idArr;	
			$("body").attr("data-ticketnum",$(".checked").length);
			url = "view/movieSchedule/sure-ticket.html";
			getPage(url); 
		}
	});	

	// 查询
	$(".query-btn").click(function(){
		getList();
		// 分页
		pageSetGet();		
	});
	/*********************************函数*******************************************/
	
	// 信息验证
	function checkMsg(){
		if($("#movieName").val() == ""){
			tips("请填写影片名称");
			$(this).focus();
			return false;
		}else if($("#filmName").val() == ""){
			tips("请填写影院名称");
			$(this).focus();
			return false;			
		}else if($("#startDate").val() == ""){
			alert("请选择开始时间");
			$(this).focus();
			return false;
		}else if($("#endDate").val() == ""){
			alert("请选择结束时间");
			$(this).focus();
			return false;
		}else{
			return true;
		}
	}


	// 获取列表
	function getList(){
		$("tbody").html("");
		$.ajax({
			url: localStorage.grobalUrl + "/schedule/scheduleList",
			type:"post",
			async:false,
			data:{
				username: username,
				token: token,
				filmName: $("#movieName").val(),
				cinemaName: $("#filmName").val(),
				beginTime: $("#startDate").val(),  
				endTime: $("#endDate").val(),  
				pageNo: pageNo,   
				pageSize: pageSize
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);
				}else if(data.scheduleList){
					totalPage = data.scheduleList.totalPage;
					totalData = data.scheduleList.totalRow;
					var dataVal = data.scheduleList.list;
					var str = '<tr align="center">'+
								'<td>'+
									'<input class="checkTicket" type="checkbox" />'+
								'</td>'+
								'<td class="schedule-id"></td>'+
								'<td class="movie-name"></td>'+
								'<td class="film-name"></td>'+
								'<td class="film-address"></td>'+
								'<td class="movie-hall"></td>'+
								'<td class="open-time"></td>'+
								'<td class="price"></td>'+
								'<td class="version"></td>'+
							'</tr>'
					for(var i = 0; i < dataVal.length; i++){
						var listVal = dataVal[i];
						$("tbody").append(str);
						$(".checkTicket").eq(i).attr("data-id",listVal.schedule_id);
						$(".schedule-id").eq(i).text(listVal.schedule_id);
						$(".movie-name").eq(i).text(listVal.film_name);
						$(".film-name").eq(i).text(listVal.cinema_name);
						$(".film-address").eq(i).text(listVal.address);
						$(".movie-hall").eq(i).text(listVal.hall_name);
						$(".open-time").eq(i).text(listVal.show_time);
						$(".price").eq(i).text(listVal.price);
						$(".version").eq(i).text(listVal.show_version);
					}
				}
			},
			error: function(err){
				console.log(err);
			}
		});
	}
	getList();

	// 分页
	pageSetGet();	




</script>
